/**
 * 
 */
package com.hexacta.hrs.report.managers;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.vectrics.employee.Employee;

import com.hexacta.hrs.report.AbstractReport;
import com.hexacta.hrs.report.dtos.CompensationDaysReportDTO;
import com.hexacta.hrs.services.employee.EmployeeService;
import com.hexacta.hrs.services.timeoff.AvailableLicenseDaysService;

import edu.emory.mathcs.backport.java.util.Collections;

/**
 * @author iandronowicz clase que genera el reporte general de dias pendientes
 *         para recuperar
 */
public class CompensationDaysReport extends AbstractReport {

    private EmployeeService employeeService;

    private AvailableLicenseDaysService availableLicenseDaysService;

    /**
     * @return the employeeService
     */
    public EmployeeService getEmployeeService() {
        return employeeService;
    }

    /**
     * @param employeeService
     *            the employeeService to set
     */
    public void setEmployeeService(final EmployeeService employeeService) {
        this.employeeService = employeeService;
    }

    /**
     * @return the availableLicenseDaysService
     */
    public AvailableLicenseDaysService getAvailableLicenseDaysService() {
        return availableLicenseDaysService;
    }

    /**
     * @param availableLicenseDaysService
     *            the availableLicenseDaysService to set
     */
    public void setAvailableLicenseDaysService(final AvailableLicenseDaysService availableLicenseDaysService) {
        this.availableLicenseDaysService = availableLicenseDaysService;
    }

    /** {@inheritDoc} */
    public ByteArrayOutputStream createPDFReport(final String reportName, final String reportTemplateLocation,
            final Map<String, Object> filters, final Map<String, Object> parameters) {
        return createPDF(reportTemplateLocation, parameters, getReportData(filters));
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.hexacta.hrs.report.Report#createXLSReport(java.lang.String,
     * java.lang.String)
     */
    public ByteArrayOutputStream createXLSReport(final String reportName, final String reportTemplateLocation,
            final Map<String, Object> filters, final Map<String, Object> parameters) {
        return createExcel(reportTemplateLocation, parameters, getReportData(filters));
    }

    @Override
    @SuppressWarnings("unchecked")
    protected Collection getReportData(final Map<String, Object> filters) {
        Collection<CompensationDaysReportDTO> collection = new ArrayList<CompensationDaysReportDTO>();
        // Levanto los compensation days
        Collection<Employee> employeeList = employeeService.getAll();
        int cantDays;

        for (Employee employee : employeeList) {

            cantDays = availableLicenseDaysService.getAvailableLicenseDays(employee).getCompensationDays();
            // Los que no tienen dias para compensar NO se muestran
            if (cantDays != 0) {
                CompensationDaysReportDTO dto = new CompensationDaysReportDTO();
                // dto.setEmployeeName(employee.getPerson().getFullName());
                dto.setEmployeeName(employee.getPerson().getLastName() + ", " + employee.getPerson().getFirstName());
                dto.setQCompensationDays(cantDays);
                collection.add(dto);
            }
        }

        if (collection.isEmpty())
            throw new RuntimeException("No data Available for Report");

        Collections.sort((List) collection);

        return collection;

    }

    @SuppressWarnings("unchecked")
    @Override
    protected Map getReportParameters() {
        // TODO Auto-generated method stub
        return null;
    }
}
